package com.higgins.eventtracking.server;

import com.higgins.eventtracking.client.IncomeSettingsService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class IncomeSettingsServiceImpl extends RemoteServiceServlet implements IncomeSettingsService {

	public String updateIncome(String income, String outgoing, String severableOutgoing) throws IllegalArgumentException {
		IncomeSettingsDataService dataService = new IncomeSettingsDataService();
		dataService.openPersistenceManager();
		try	{
			dataService.updateIncome(income, outgoing, severableOutgoing);
			dataService.closePersistenceManager();
			return "Update was successful for income (" +  income + ", " + outgoing + "," + severableOutgoing + ").\n";
		} catch (Exception e)	{
			dataService.closePersistenceManager();
			return "Update was unsuccessful for income.\n";
		}		
	}

	@Override
	public String retrieveIncome() throws IllegalArgumentException {
		String result = null;
		IncomeSettingsDataService dataService = new IncomeSettingsDataService();
		dataService.openPersistenceManager();
		try	{
			return dataService.retrieveIncome();
		} catch (Exception e)	{
			return "Retrival was unsuccessful.\n";
		} finally {
			dataService.closePersistenceManager();
		}
	}

	@Override
	public String retrieveOutgoing() throws IllegalArgumentException {
		String result = null;
		IncomeSettingsDataService dataService = new IncomeSettingsDataService();
		dataService.openPersistenceManager();
		try	{
			return dataService.retrieveOutgoing();
		} catch (Exception e)	{
			return "Retrival was unsuccessful.\n";
		} finally {
			dataService.closePersistenceManager();
		}
	}
	@Override
	public String retrieveSeverableOutgoing() throws IllegalArgumentException {
		String result = null;
		IncomeSettingsDataService dataService = new IncomeSettingsDataService();
		dataService.openPersistenceManager();
		try	{
			return dataService.retrieveSeverableOutgoing();
		} catch (Exception e)	{
			return "Retrival was unsuccessful.\n";
		} finally {
			dataService.closePersistenceManager();
		}
	}
	
}
